home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_11 / phillip2 / cips5.c < prev    next >
C/C++ Source or Header  |  1993-09-22  |  44KB  |  1,584 lines

  1.  
  2.    /*************************** 
  3.    * 
  4.    *   cips5.c 
  5.    *   COMPOSITE FILE COMPRISING: 
  6.    *   boole.c 
  7.    *   overlay.c 
  8.    *   txtrsubs.c 
  9.    * 
  10.    ***************************\ 
  11.  
  12.  
  13.  
  14.  
  15.     /***********************************************
  16.     *
  17.     *       file d:\cips\boole.c
  18.     *
  19.     *       Functions: This file contains
  20.     *          and_image
  21.     *          or_image
  22.     *          xor_image
  23.     *          nand_image
  24.     *          nor_image
  25.     *          not_image
  26.     *
  27.     *       Purpose:
  28.     *          These functions implement the basic
  29.     *          Boolean algebra functions AND, OR,
  30.     *          XOR, NAND, NOR, and NOT.
  31.     *
  32.     *       External Calls:
  33.     *          wtiff.c - create_file_if_needed
  34.     *                    write_array_into_tiff_image
  35.     *          tiff.c - read_tiff_header
  36.     *          rtiff.c - read_tiff_image
  37.     *          numcvrt.c - get_integer
  38.     *
  39.     *       Modifications:
  40.     *          3 March 1993 - created
  41.     *
  42.     ***********************************************/
  43.  
  44.  
  45. #include "cips.h"
  46.  
  47.  
  48.  
  49.    /**************************************************
  50.    *
  51.    *   and_image(...
  52.    *
  53.    *   This function performs the Boolean AND 
  54.    *   operation.  The output image = in1 AND in2.
  55.    *   This works for 0 non-zero images.  If both
  56.    *   in1 and in2 are non-zero, the output = in1.
  57.    *
  58.    ***************************************************/
  59.  
  60. and_image(in1_name, in2_name, out_name,
  61.           the_image, out_image,
  62.           il1, ie1, ll1, le1,
  63.           il2, ie2, ll2, le2,
  64.           il3, ie3, ll3, le3)
  65.    char   in1_name[], in2_name[], out_name[];
  66.    int    il1, ie1, ll1, le1,
  67.           il2, ie2, ll2, le2,
  68.           il3, ie3, ll3, le3;
  69.    short  the_image[ROWS][COLS],
  70.           out_image[ROWS][COLS];
  71. {
  72.    int    i, j, length, width;
  73.    struct tiff_header_struct image_header;
  74.  
  75.    create_file_if_needed(in1_name, out_name, out_image);
  76.  
  77.    read_tiff_image(in1_name, the_image,
  78.                    il1, ie1, ll1, le1);
  79.    read_tiff_image(in2_name, out_image,
  80.                    il2, ie2, ll2, le2);
  81.  
  82.    for(i=0; i<ROWS; i++){
  83.       if ( (i%10) == 0) printf(" %d", i);
  84.       for(j=0; j<COLS; j++){
  85.          if( the_image[i][j] != 0   &&
  86.              out_image[i][j] != 0)
  87.              out_image[i][j] = the_image[i][j];
  88.          else
  89.              out_image[i][j] = 0;
  90.       }  /* ends loop over j */
  91.    }  /* ends loop over i */
  92.  
  93.    write_array_into_tiff_image(out_name, out_image,
  94.                                il3, ie3, ll3, le3);
  95.  
  96. } /* ends and_image */
  97.  
  98.  
  99.  
  100.  
  101.  
  102.    /**************************************************
  103.    *
  104.    *   or_image(...
  105.    *
  106.    *   This function performs the Boolean OR 
  107.    *   operation.  The output image = in1 OR in2.
  108.    *   This works for 0 non-zero images.  If both
  109.    *   in1 and in2 are non-zero, the output = in1.
  110.    *   If in1 is non-zero, the output = in1.
  111.    *   If in1 is zero and in2 is non-zero, the
  112.    *   output = in2.
  113.    *
  114.    ***************************************************/
  115.  
  116. or_image(in1_name, in2_name, out_name,
  117.          the_image, out_image,
  118.          il1, ie1, ll1, le1,
  119.          il2, ie2, ll2, le2,
  120.          il3, ie3, ll3, le3)
  121.    char  in1_name[], in2_name[], out_name[];
  122.    int   il1, ie1, ll1, le1,
  123.          il2, ie2, ll2, le2,
  124.          il3, ie3, ll3, le3;
  125.    short the_image[ROWS][COLS],
  126.          out_image[ROWS][COLS];
  127. {
  128.    int    i, j, length, width;
  129.    struct tiff_header_struct image_header;
  130.  
  131.    create_file_if_needed(in1_name, out_name, out_image);
  132.  
  133.    read_tiff_image(in1_name, the_image,
  134.                    il1, ie1, ll1, le1);
  135.    read_tiff_image(in2_name, out_image,
  136.                    il2, ie2, ll2, le2);
  137.  
  138.    for(i=0; i<ROWS; i++){
  139.       if ( (i%10) == 0) printf(" %d", i);
  140.       for(j=0; j<COLS; j++){
  141.          if( the_image[i][j] != 0   ||
  142.              out_image[i][j] != 0){
  143.              if(the_image[i][j] != 0)
  144.                 out_image[i][j] = the_image[i][j];
  145.              else
  146.                 out_image[i][j] = out_image[i][j];
  147.          }
  148.          else
  149.              out_image[i][j] = 0;
  150.       }  /* ends loop over j */
  151.    }  /* ends loop over i */
  152.  
  153.    write_array_into_tiff_image(out_name, out_image,
  154.                                il3, ie3, ll3, le3);
  155.  
  156. } /* ends or_image */
  157.  
  158.  
  159.  
  160.  
  161.  
  162.    /**************************************************
  163.    *
  164.    *   xor_image(...
  165.    *
  166.    *   This function performs the Boolean XOR 
  167.    *   operation.  The output image = in1 XOR in2.
  168.    *   This works for 0 non-zero images.  If 
  169.    *   in1 is non-zero and in2 is 0, output = in1. If
  170.    *   in2 is non-zero and in1 is 0, output = in2.
  171.    *   If both in1 and in2 are non-zero, output = 0.
  172.    *   If both in1 and in2 are zero, output = 0.
  173.    *
  174.    ***************************************************/
  175.  
  176. xor_image(in1_name, in2_name, out_name,
  177.           the_image, out_image,
  178.           il1, ie1, ll1, le1,
  179.           il2, ie2, ll2, le2,
  180.           il3, ie3, ll3, le3)
  181.    char   in1_name[], in2_name[], out_name[];
  182.    int    il1, ie1, ll1, le1,
  183.           il2, ie2, ll2, le2,
  184.           il3, ie3, ll3, le3;
  185.    short  the_image[ROWS][COLS],
  186.           out_image[ROWS][COLS];
  187. {
  188.    int    i, j, length, width;
  189.    short  answer;
  190.    struct tiff_header_struct image_header;
  191.  
  192.    create_file_if_needed(in1_name, out_name, out_image);
  193.  
  194.    read_tiff_image(in1_name, the_image,
  195.                    il1, ie1, ll1, le1);
  196.    read_tiff_image(in2_name, out_image,
  197.                    il2, ie2, ll2, le2);
  198.  
  199.    for(i=0; i<ROWS; i++){
  200.       if ( (i%10) == 0) printf(" %d", i);
  201.       for(j=0; j<COLS; j++){
  202.          if( (the_image[i][j] != 0 &&
  203.               out_image[i][j] == 0))
  204.              answer = the_image[i][j];
  205.          if( (the_image[i][j] == 0 &&
  206.               out_image[i][j] != 0))
  207.              answer = out_image[i][j];
  208.          if( (the_image[i][j] == 0 &&
  209.               out_image[i][j] == 0))
  210.              answer = 0;
  211.          if( (the_image[i][j] != 0 &&
  212.               out_image[i][j] != 0))
  213.              answer = 0;
  214.          out_image[i][j] = answer;
  215.       }  /* ends loop over j */
  216.    }  /* ends loop over i */
  217.  
  218.    write_array_into_tiff_image(out_name, out_image,
  219.                                il3, ie3, ll3, le3);
  220.  
  221. } /* ends xor_image */
  222.  
  223.  
  224.  
  225.  
  226.  
  227.    /**************************************************
  228.    *
  229.    *   nand_image(...
  230.    *
  231.    *   This function performs the Boolean NAND 
  232.    *   operation.  The output image = in1 NAND in2.
  233.    *   This works for 0 non-zero images.  If both
  234.    *   in1 and in2 are non-zero, the output = 0.
  235.    *   Otherwise, the output = value.
  236.    *
  237.    ***************************************************/
  238.  
  239. nand_image(in1_name, in2_name, out_name,
  240.            the_image, out_image,
  241.            il1, ie1, ll1, le1,
  242.            il2, ie2, ll2, le2,
  243.            il3, ie3, ll3, le3, value)
  244.    char    in1_name[], in2_name[], out_name[];
  245.    int     il1, ie1, ll1, le1,
  246.            il2, ie2, ll2, le2,
  247.            il3, ie3, ll3, le3;
  248.    short   the_image[ROWS][COLS],
  249.            out_image[ROWS][COLS], value;
  250. {
  251.    int    i, j, length, width;
  252.    struct tiff_header_struct image_header;
  253.  
  254.    create_file_if_needed(in1_name, out_name, out_image);
  255.  
  256.    read_tiff_image(in1_name, the_image,
  257.                    il1, ie1, ll1, le1);
  258.    read_tiff_image(in2_name, out_image,
  259.                    il2, ie2, ll2, le2);
  260.  
  261.    for(i=0; i<ROWS; i++){
  262.       if ( (i%10) == 0) printf(" %d", i);
  263.       for(j=0; j<COLS; j++){
  264.          if( the_image[i][j] != 0   &&
  265.              out_image[i][j] != 0)
  266.              out_image[i][j] = 0;
  267.          else
  268.              out_image[i][j] = value;
  269.       }  /* ends loop over j */
  270.    }  /* ends loop over i */
  271.  
  272.    write_array_into_tiff_image(out_name, out_image,
  273.                                il3, ie3, ll3, le3);
  274.  
  275. } /* ends nand_image */
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.    /**************************************************
  283.    *
  284.    *   nor_image(...
  285.    *
  286.    *   This function performs the Boolean NOR 
  287.    *   operation.  The output image = in1 NOR in2.
  288.    *   This works for 0 non-zero images.  If niether